import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hixing_app/const/color_res.dart';
import 'package:hixing_app/views/test_view/ble_machine/BleDataUtils.dart';

class HomeIndex extends StatefulWidget {
  const HomeIndex({super.key});

  @override
  _HomeIndexState createState() => _HomeIndexState();
}

class _HomeIndexState extends State<HomeIndex> {
  BoxDecoration _decoration1 = BoxDecoration(color: Colors.transparent);
  BoxDecoration _decoration2 = BoxDecoration(
      gradient: LinearGradient(colors: [Colors.orange, Colors.yellow]));
  BoxDecoration? _decoration;
  bool showFirst = true;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    var _str = BleDataUtils.intToNBytesHex(1000, 2, isSplit: false);
    print("1000拆分成多字节的 16进制字符串:${_str}");
    List<int> _list = [170, 187];
    List<String> _hexStr = BleDataUtils.listIntToHex(_list);
    print("list<int>转16进制字符串：${_hexStr}");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('home首页'),
        backgroundColor: Colors.blueAccent,
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const Spacer(),
            Listener(
              onPointerUp: (_) {
                setState(() {
                  _decoration = _decoration1;
                });
              },
              onPointerHover: (_) {
                print("hover中...");
                setState(() {
                  _decoration = _decoration2;
                });
              },
              // onPointerDown: (_) {
              //   print("点击..");
              //   setState(() {
              //     _decoration = _decoration2;
              //   });
              // },
              child: AnimatedContainer(
                duration: Duration(milliseconds: 200),
                height: 50,
                width: 50,
                decoration: _decoration,
                child: Text("版画"),
              ),
            ),
            AnimatedCrossFade(
                firstChild: Container(),
                secondChild: Container(
                  width: double.infinity,
                  color: Colors.black,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Text("data"),
                      Container(
                        height: 100,
                        color: Colors.red,
                      )
                    ],
                  ),
                ),
                crossFadeState: showFirst
                    ? CrossFadeState.showFirst
                    : CrossFadeState.showSecond,
                duration: Duration(milliseconds: 2000)),
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    showFirst = !showFirst;
                  });
                },
                child: Text("显示/隐藏")),
            Container(
              child: Text("12321321"),
            )
          ],
        ),
      ),
    );
  }
}
